#coding=utf-8
'''
Created on 2010-10-20

@author: tongji
@contact: tongji@rekoo.com
@todo: 需要程序员实现两个回调函数
'''
import datetime


from farm_lib.models.game_info import GameInfo

def BASEDATA(key, request, *args, **kwargs):
    '''
    这个是日志中的固定数据，比如用户uid，等级等信息
    key: 例如views.user.home
    request: request对象
    args, kwargs: 请求的其他参数
    '''
    try:
        rk_user = request.rk_user
        try:
            stay = (datetime.datetime.now() - rk_user.add_time).days +1
            stay = stay if stay < 4 else 0
        except:
            stay = 0
        data = {
                'uid':rk_user.uid, 
                'action':key, 
                'scene':'k', 
                'level':rk_user.game_info.level,
                'stay':stay, 
                'success':True, 
                'num':1
                }
    except Exception, e:
        data = {
                'uid':-1, 
                'action':key,  
                'scene':'k', 
                'level':-1,
                'stay':-1, 
                'success':True, 
                'num':1
                }
    return data


def ARGSDATA(request, *args, **kwargs):
    '''
    这个函数很重要，请后端人员维护；请尽量保持这个函数的效率，因为它会在每次视图函数中调用两次，要防止这个函数成为瓶颈
    请简单地返回一个字典， 这个字典里的数据是你需要前后比较的数据，比如说金币
    一旦测试完成之后，请不要随意改动，因为这直接影响到日志数据
    '''
    data = {}
    try:
        game_info = GameInfo.get(request.rk_user.uid)
        data['gold'] = game_info.gold
        data['points'] = game_info.points
        data['exp'] = game_info.exp
        data['level'] = game_info.level
        data['energy'] = game_info.energy
        data['co2'] = game_info.co2
        data['o2'] = game_info.o2
        data['unit_time_earnings'] = game_info.unit_time_earnings
        data['tax_building_total'] = game_info.tax_building_total
        data['invite_score'] = game_info.invite_score
        data['explore_total'] = game_info.explore_total
    except Exception, e:
        pass
    return data


